import { Controller, Get, Post, Body, Param, Put, Delete, ParseUUIDPipe, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import type { IDictData, IPaginationResponse } from '@nbase/shared';
import { DictDataService } from './dict-data.service';
import { CreateDictDataDto } from './dto/create-dict-data.dto';
import { UpdateDictDataDto } from './dto/update-dict-data.dto';
import { QueryDictDataDto } from './dto/query-dict-data.dto';

@ApiTags('system/dict-data')
@ApiBearerAuth('JWT-auth')
@Controller('system/dict-data')
export class DictDataController {
  constructor(private readonly dictDataService: DictDataService) {}

  @ApiOperation({ summary: '获取字典数据列表' })
  @ApiResponse({ status: 200, description: '获取成功' })
  @Get()
  findAll(@Query() query: QueryDictDataDto): Promise<IPaginationResponse<IDictData>> {
    return this.dictDataService.paginateDictData(query);
  }

  @ApiOperation({ summary: '获取字典数据详情' })
  @ApiParam({ name: 'id', description: '字典数据ID', type: String })
  @ApiResponse({ status: 200, description: '获取成功' })
  @ApiResponse({ status: 404, description: '字典数据不存在' })
  @Get(':id')
  findOne(@Param('id', ParseUUIDPipe) id: string): Promise<IDictData> {
    return this.dictDataService.findById(id);
  }

  @ApiOperation({ summary: '创建字典数据' })
  @ApiResponse({ status: 201, description: '创建成功' })
  @ApiResponse({ status: 400, description: '参数错误' })
  @Post()
  create(@Body() createDictDataDto: CreateDictDataDto): Promise<IDictData> {
    return this.dictDataService.createDictData(createDictDataDto);
  }

  @ApiOperation({ summary: '更新字典数据' })
  @ApiParam({ name: 'id', description: '字典数据ID', type: String })
  @ApiResponse({ status: 200, description: '更新成功' })
  @ApiResponse({ status: 404, description: '字典数据不存在' })
  @Put(':id')
  update(@Param('id', ParseUUIDPipe) id: string, @Body() updateDictDataDto: UpdateDictDataDto): Promise<IDictData> {
    return this.dictDataService.updateDictData(id, updateDictDataDto);
  }

  @ApiOperation({ summary: '删除字典数据' })
  @ApiParam({ name: 'id', description: '字典数据ID', type: String })
  @ApiResponse({ status: 200, description: '删除成功' })
  @ApiResponse({ status: 404, description: '字典数据不存在' })
  @Delete(':id')
  async remove(@Param('id', ParseUUIDPipe) id: string): Promise<void> {
    await this.dictDataService.deleteDictData(id);
  }
}

